<?php
/**
 * Created by PhpStorm.
 * User: yandian
 * Date: 16/8/6
 * Time: 20:23
 */

namespace app\common\util;


class DateTimeUtil
{
    public static function now()
    {
        return date('Y-m-d H:i:s');
    }

    public static function differDays($date, $new_date = null)
    {
        if ($new_date == null) {
            $new_date = date('Y-m-d');
        }
        $date = strtotime($date);
        $new_date = strtotime($new_date);
        return ceil(($date - $new_date) / 86400);
    }

    public static function passedDays($passedDate)
    {
        if (($pos = strpos($passedDate, ' ')) > 0) {
            $passedDate = substr($passedDate, 0, $pos);
        }
        return self::differDays(date('Y-m-d'), $passedDate);
    }

    public static function dateOftoday()
    {
        return date('Y-m-d');
    }
}